<?php
namespace app\common\model;


use app\api\controller\Base;
use think\Model;

class Reason extends Model
{

    public function user()
    {
        return $this->hasOne('users', 'user_id', 'id')->field('nick_name');
    }

    public function users()
    {
        return $this->hasOne('users', 'user_id', 'user_id')->field('nick_name');
    }


    public function room()
    {
        return $this->hasOne('room', 'room_id', 'id')->field('room_name');
    }


    public function getRoomList($map = [])
    {
        return $this->alias('r')
            ->join('room rm','rm.room_id = r.id','LEFT')
            ->join('users u','u.user_id = r.user_id','LEFT')
            ->where($map)
            ->field('r.imgs,r.type,r.report_id,r.reason,r.status,r.create_time,r.update_time,r.user_id,r.id,rm.room_name as name,u.nick_name')
            ->order('r.create_time desc')
            ->paginate('',false,['query'=>request()->param()]);
    }


    public function getUserList($map = [])
    {
        return $this->alias('r')
            ->join('users u','u.user_id = r.user_id','LEFT')
            ->join('users us','us.user_id = r.id','LEFT')
            ->where($map)
            ->field('r.type,r.report_id,r.reason,r.status,r.create_time,r.update_time,r.user_id,r.id,us.nick_name as name,u.nick_name')
            ->order('r.create_time desc')
            ->paginate('',false,['query'=>request()->param()]);
    }

    /*
            * 后台举报详情
            */
    public function detail($id){
        $row = $this->where(['report_id'=>$id])->find();
        if($row['type']==1){
            $row['name'] = Base::StaticRoomInfo($row['id'],'room_name');
        }elseif ($row['type']==2){
            $row['name']= Base::staticInfo('nick_name',$row['id']);
        }
        $row['imgs'] = $row['imgs']?explode(',',$row['imgs']):[];
        return $row;
    }



}